package com.cx.cxapi;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.display.DisplayManager;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.cx.cxapi.util.Util;
import com.jws.thirdlibrary.CxManager;
import com.cx.cxapi.uninstall.WhitelistUninstallActivity;
import com.jws.thirdlibrary.ICustomCallback;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;

public class MainActivity extends Activity implements OnClickListener, CompoundButton.OnCheckedChangeListener, AdapterView.OnItemSelectedListener {
    private static final String TAG = "JwsApi";
    public static final String REQUEST_RESPONSE_IR_STATE_ACTION = "android.provider.JWS.REQUEST_RESPONSE_IR_STATE";
    public static final String EXTRA_IR_STATE_RESPONSE = "IRSTATERESPONSE";
    private CxManager mCxManager;
    private AudioManager mAudioManager;

    private Button button_close;
    private Button btn_gpio;
    private Button btn_devices;
    private Button btn_uart;
    private Button btn_io_closeback;
    private Button button_reboot;
    private Button btn_update;
    private Button btn_openwifi;
    private Button btn_closewifi;
    private Button button_get_nettype;
    private Button btn_normal;
    private Button button_settimebynetoff;
    private Button button_takePictrue;
    private Button btn_watchdog;
    private Button btn_closedog;
    private Button btn_feeddog;
    private Button btn_set_watch_dog_timeout;
    private Button btn_get_watch_dog_timeout;
    private EditText et_interval;
    private EditText et_margin;
    private Button button_settime;
    private Button btn_sd;
    private Button btn_USB;
    private Button btn_openUsb;
    private Button btn_closeUsb;
    private Button btn_getEth;
    private Button button_settimebyNet;
    private Button btn_volumeadd;
    private Button btn_volumedec;
    private Button btn_mute_restore;
    private Button btn_silent_install_only;
    private Button btn_silent_install_self_starting;
    private Button btn_openback;
    private Button btn_closeback;
    private Button btn_getback;
    private Button btn_set_power_off_on_time;
    private Button btn_showstatus;
    private Button btn_hidestatus;
    private Button btn_one;
    private Button btn_two;
    private Button btn_three;
    private Button btn_four;
	private Button btn_hdmi_one;
	private Button btn_hdmi_two;
	private Button btn_hdmi_three;
	private Button btn_hdmi_four;
    private Button btn_setVolume;
    private Button btn_getVolume;
    private Button btn_getBright;
    private Button btn_openlog;
    private Button btn_closelog;
    private Spinner slogtype;
    private Button btn_getMac;
    private Button btn_setIP;
    private Button btn_dhcp;
    private CheckBox ethernet_checkbox;
    private CheckBox jws_et_ethernet_checkbox;
    private EditText edit_ipAddr;
    private EditText edit_netMask;
    private EditText edit_gateway;
    private EditText edit_dns1;
    private EditText edit_dns2;

    private Button btn_getIP;
    private EditText et_year;
    private EditText et_month;
    private EditText et_day;
    private EditText et_hour;
    private EditText et_minute;
    private EditText et_second;
    private EditText poweroff_hour;
    private EditText poweroff_minute;
    private EditText poweron_hour;
    private EditText poweron_minute;

    private EditText edit_values;
    private EditText edit_setBright;
    private EditText edit_enable;
    private TextView editNetType;
    private TextView txt_volume_show;
    private TextView tv_bright;
    private TextView tv_Mac;
    private TextView tv_IP;
    private TextView tv_usb;
    private TextView tv_sd;
    private TextView tv_eth;
    private EditText tv_usbNum;
    private Button btn_openEthPower;
    private Button btn_closeEthPower;

    private Button btn_screenWidth;
    private Button btn_screenHeight;
    private TextView tv_screenWidth;
    private TextView tv_screenHeight;

    private TextView tv_read_eeprom;
    private EditText ed_usb_num;
    private EditText et_eeprom_data;
    private EditText et_deviceId;
    private EditText et_areaId;
    private EditText et_start_addr;
    private EditText et_size;
    private Button btn_write_eeprom;
    private Button btn_read_eeprom;

    private TextView tv_api_version;
    private Button btn_get_api_version;

    //3G
    private Button btn_3G_open;
    private Button btn_3G_close;
    private Button btn_3G_reset;
    private Button btn_imei;
    private TextView tv_imei;

    //led
    private Button btn_led_open;
    private Button btn_led_close;

    //mic
    private Button btn_headsetmic_open;
    private Button btn_headsetmic_close;

    private Button btn_speaker;
    private Button btn_output_normal;

    private Button btn_three_poweronoff;

    //HDMI output
    private Button btn_hdmi_open;
    private Button btn_hdmi_close;

    //audio output device force use
    private Button btn_audio_speaker;
    private Button btn_audio_wired_headset;
    private Button btn_audio_usb_headset;
    private Button btn_audio_aux_digital;
    private Button btn_audio_bluetooth_a2dp;

    //usb2.0/3.0 TypeA enable/disable
    private Button btn_usb2_open;
    private Button btn_usb2_close;
    private Button btn_usb3_open;
    private Button btn_usb3_close;
    //HDMI connect status
    private Button btn_hdmi_connect_status;
    //HDMIIN connect status
//    private Button btn_hdmiin_connect_status;
    //packages whitelist
    private Button btn_whitelist_control;

    //otg mode
    private Button btn_otg_mode_slave;
    private Button btn_otg_mode_host;
    private Button btn_otg_mode_mode;

    //touchscreen
    private Button btn_ts_enable;
    private Button btn_ts_disable;
    private Button btn_ts_status;
    private Button btn_ir_open;
    private Button btn_ir_close;

    //	//wifi white list
    private Button btnDeleWifiWhitelist, btnGetWifiWhitelist, btnRemoveWifiWhitelist, btnAddWifiWhitelist;
    private EditText etRemoveWifiWhitelist, etAddWifiWhitelist;
    //net whitelist
    private Button btn_Firewall, btn_Firewall_disable, btn_disabled_mobile, btn_disabled_wifi, btn_disable_eth;
    private Button btn_clear_mobile, btn_clear_wifi, btn_clear_eth;
    private Button btn_get_app_whitelist, btn_get_url_whitelist, btn_get_app_blacklist, btn_get_url_blacklist;
    Button btn_uninstall_package;
    private Button btn_app_whitelist, btn_app_blacklist, btn_url_whitelist, btn_url_blacklist;
    private EditText etAppWhiteList, etAppBlackList, etUrlWhiteList, etUrlBlackList;
    private Button btn_net_time_limit, btn_net_weekdays_limit;
    private EditText et_net_start_limit_hour, et_net_start_limit_minute, et_net_end_limit_hour, et_net_end_limit_minute;
    private EditText et_net_limit_weekdays;
    private Button btn_keep_alive_on,btn_keep_alive_off,btn_get_keep_alive_pkg_name,btn_clear_keep_alive_pkg_name,btn_set_keep_alive_pkg_name,btn_set_keep_alive_interval_time,btn_get_keep_alive_interval_time,btn_set_keep_alive_service_pkg,btn_get_keep_alive_service_pkg;
    private EditText et_set_keep_alive_pkg_name,et_set_keep_alive_service_pkg,et_set_keep_alive_interval_time;
    private Button btn_wifi_tether_on,btn_wifi_tether_off,btn_wifi_tether_ssidpwd,btn_wifi_tether_ip,btn_get_wifi_tether_enabled,btn_get_wifi_tether_ssid,btn_get_wifi_tether_pwd,btn_get_wifi_tether_ip;
    private EditText et_wifi_tether_ssid,et_wifi_tether_pwd,et_wifi_tether_band,et_wifi_tether_ip;
	private Button btn_set_logo,btn_set_default_wallpaper,btn_set_boot_animation,btn_reset_boot_animation;
	private EditText et_set_logo,et_set_default_wallpaper,et_set_boot_animation;
	private Button btn_set_default_locale,btn_set_default_timezone;
	private EditText et_set_default_locale,et_set_default_timezone;
    private Button btn_can_api;
    private static final int ADJUST_MUTE = -100;
    private static final int ADJUST_UNMUTE = 100;
    private static final int ADJUST_LOWER = -1;
    private static final int ADJUST_RAISE = 1;
    private static final int ADJUST_SAME = 0;
    private static final int FLAG_SHOW_UI = 1 << 0;
    private static final int ADJUST_TOGGLE_MUTE = 101;

    private static int mPoweroffRepeatType = 0;
    private Spinner spinner_poweroff_repeat_type;
    private ToggleButton toggle_scheduled_poweroff;
    private EditText et_poweroff_hour;
    private EditText et_poweroff_minute;
    private EditText et_poweroff_repeat_week;

    private static int mPoweronRepeatType = 0;
    private Spinner spinner_poweron_repeat_type;
    private ToggleButton toggle_scheduled_poweron;
    private EditText et_poweron_hour;
    private EditText et_poweron_minute;
    private EditText et_poweron_repeat_week;

    private static int mPoweroffRepeatType2 = 0;
    private Spinner spinner_poweroff_repeat_type2;
    private ToggleButton toggle_scheduled_poweroff2;
    private EditText et_poweroff_hour2;
    private EditText et_poweroff_minute2;
    private EditText et_poweroff_repeat_week2;

    private static int mPoweronRepeatType2 = 0;
    private Spinner spinner_poweron_repeat_type2;
    private ToggleButton toggle_scheduled_poweron2;
    private EditText et_poweron_hour2;
    private EditText et_poweron_minute2;
    private EditText et_poweron_repeat_week2;
    /**
     * The audio stream for phone calls
     */
    private static final int STREAM_VOICE_CALL = 0;
    /**
     * The audio stream for system sounds
     */
    private static final int STREAM_SYSTEM = 1;
    /**
     * The audio stream for the phone ring
     */
    private static final int STREAM_RING = 2;
    /**
     * The audio stream for music playback
     */
    private static final int STREAM_MUSIC = 3;
    /**
     * The audio stream for alarms
     */
    private static final int STREAM_ALARM = 4;
    /**
     * The audio stream for notifications
     */
    private static final int STREAM_NOTIFICATION = 5;
    /**
     * @hide The audio stream for phone calls when connected to bluetooth
     */
    private static final int STREAM_BLUETOOTH_SCO = 6;
    /**
     * @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan)
     */
    private static final int STREAM_SYSTEM_ENFORCED = 7;
    /**
     * The audio stream for DTMF Tones
     */
    private static final int STREAM_DTMF = 8;
    /**
     * @hide The audio stream for text to speech (TTS)
     */
    private static final int STREAM_TTS = 9;

    jwsInfraredReceiver mInfraredReceiver;

    @SuppressLint("HandlerLeak")
    Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 0x123) {
                Toast.makeText(MainActivity.this, "进入截图功能", Toast.LENGTH_SHORT).show();
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAudioManager = (AudioManager) getSystemService(Service.AUDIO_SERVICE);
        button_close = (Button) findViewById(R.id.button_close);
        button_reboot = (Button) findViewById(R.id.button_reboot);
        button_get_nettype = (Button) findViewById(R.id.button_get_nettype);
        button_takePictrue = (Button) findViewById(R.id.button_takepictrue);
        button_settime = (Button) findViewById(R.id.button_settime);
        button_settimebyNet = (Button) findViewById(R.id.button_settimebynet);
        button_settimebynetoff = (Button) findViewById(R.id.button_settimebynetoff);
        btn_silent_install_only = (Button) findViewById(R.id.btn_silent_install_only);
        btn_silent_install_self_starting = (Button) findViewById(R.id.btn_silent_install_self_starting);
        editNetType = (TextView) findViewById(R.id.edit_get_net_type);
        tv_Mac = (TextView) findViewById(R.id.tv_showMac);
        tv_IP = (TextView) findViewById(R.id.tv_showIP);
        txt_volume_show = (TextView) findViewById(R.id.txt_volume_show);
        tv_sd = (TextView) findViewById(R.id.tv_sd);
        tv_usb = (TextView) findViewById(R.id.tv_USB);
        tv_bright = (TextView) findViewById(R.id.tv_bright);
        tv_eth = (TextView) findViewById(R.id.tv_eth);
        btn_set_power_off_on_time = (Button) findViewById(R.id.set_power_off_on_time);
        et_year = (EditText) findViewById(R.id.et_year);
        et_month = (EditText) findViewById(R.id.et_month);
        et_day = (EditText) findViewById(R.id.et_day);
        et_hour = (EditText) findViewById(R.id.et_hour);
        et_minute = (EditText) findViewById(R.id.et_minute);
        et_second = (EditText) findViewById(R.id.et_second);
        poweroff_hour = (EditText) findViewById(R.id.poweroff_hour);
        poweroff_minute = (EditText) findViewById(R.id.poweroff_minute);
        poweron_hour = (EditText) findViewById(R.id.poweron_hour);
        poweron_minute = (EditText) findViewById(R.id.poweron_minute);
        edit_values = (EditText) findViewById(R.id.edit_values);
        edit_setBright = (EditText) findViewById(R.id.edit_setBright);
        edit_enable = (EditText) findViewById(R.id.edit_enable);
        tv_usbNum = (EditText) findViewById(R.id.tv_usbNum);
        btn_gpio = (Button) findViewById(R.id.btn_gpio);
        btn_devices = (Button) findViewById(R.id.btn_devices);
        btn_uart = (Button) findViewById(R.id.btn_uart);
        btn_update = (Button) findViewById(R.id.btn_update);
        btn_showstatus = (Button) findViewById(R.id.btn_showstatus);
        btn_hidestatus = (Button) findViewById(R.id.btn_hidestatus);
        btn_openback = (Button) findViewById(R.id.btn_openback);
        btn_closeback = (Button) findViewById(R.id.btn_closeback);
        btn_io_closeback = (Button) findViewById(R.id.btn_bright);
        btn_volumeadd = (Button) findViewById(R.id.btn_volumeadd);
        btn_volumedec = (Button) findViewById(R.id.btn_volumedec);
        btn_mute_restore = (Button) findViewById(R.id.btn_mute_restore);
        btn_normal = (Button) findViewById(R.id.btn_normal);
        btn_one = (Button) findViewById(R.id.btn_one);
        btn_two = (Button) findViewById(R.id.btn_two);
        btn_three = (Button) findViewById(R.id.btn_three);
        btn_four = (Button) findViewById(R.id.btn_four);
		btn_hdmi_one = (Button)findViewById(R.id.btn_hdmi_one);
		btn_hdmi_two = (Button)findViewById(R.id.btn_hdmi_two);
		btn_hdmi_three = (Button)findViewById(R.id.btn_hdmi_three);
		btn_hdmi_four = (Button)findViewById(R.id.btn_hdmi_four);	
        btn_setVolume = (Button) findViewById(R.id.btn_setVolume);
        btn_getVolume = (Button) findViewById(R.id.btn_getVolume);
        btn_getBright = (Button) findViewById(R.id.btn_getBright);
        btn_openlog = (Button) findViewById(R.id.btn_openlog);
        btn_closelog = (Button) findViewById(R.id.btn_closelog);
        slogtype = (Spinner) findViewById(R.id.logcat_typeid);
        btn_getMac = (Button) findViewById(R.id.btn_getmac);
        btn_setIP = (Button) findViewById(R.id.btn_setIP);
        btn_dhcp = (Button) findViewById(R.id.btn_dhcp);
        btn_can_api = (Button) findViewById(R.id.btn_can_api);
        ethernet_checkbox = (CheckBox) findViewById(R.id.ethernet_checkbox);
        ethernet_checkbox.setText(R.string.jws_btn_ethernet_checkbox);
        boolean checked = ethernet_checkbox.isChecked();
        Log.i(TAG, "checked: " + checked);

        ethernet_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Log.i(TAG, "onCheckedChanged: " + isChecked);
                boolean checked = ethernet_checkbox.isChecked();
                Log.i(TAG, "checked: " + checked);
            }
        });

        jws_et_ethernet_checkbox = (CheckBox) findViewById(R.id.jws_et_ethernet_checkbox);
        jws_et_ethernet_checkbox.setText(R.string.jws_btn_ethernet_checkbox);
        boolean jws_et_checked = jws_et_ethernet_checkbox.isChecked();
        Log.i(TAG, "jws_et_checked: " + jws_et_checked);
        edit_ipAddr = (EditText) findViewById(R.id.edit_ipAddr);
        edit_netMask = (EditText) findViewById(R.id.edit_netMask);
        edit_gateway = (EditText) findViewById(R.id.edit_gateway);
        edit_dns1 = (EditText) findViewById(R.id.edit_dns1);
        edit_dns2 = (EditText) findViewById(R.id.edit_dns2);
        btn_getIP = (Button) findViewById(R.id.btn_getIP);
        btn_USB = (Button) findViewById(R.id.btn_USB);
        ed_usb_num = (EditText) findViewById(R.id.edit_usb_num);
        btn_sd = (Button) findViewById(R.id.btn_sd);
        btn_watchdog = (Button) findViewById(R.id.btn_watchdog);
        btn_closedog = (Button) findViewById(R.id.btn_closedog);
        btn_feeddog = (Button) findViewById(R.id.btn_feeddog);
        btn_set_watch_dog_timeout = (Button)findViewById(R.id.btn_set_watch_dog_timeout);
        btn_get_watch_dog_timeout = (Button)findViewById(R.id.btn_get_watch_dog_timeout);
        et_interval = (EditText)findViewById(R.id.et_interval);
        et_margin = (EditText)findViewById(R.id.et_margin);

        btn_openUsb = (Button) findViewById(R.id.btn_openUSB);
        btn_closeUsb = (Button) findViewById(R.id.btn_closeUSB);
        btn_getEth = (Button) findViewById(R.id.btn_getEth);
        btn_getback = (Button) findViewById(R.id.btn_getback);
        btn_openEthPower = (Button) findViewById(R.id.btn_openEthPower);
        btn_closeEthPower = (Button) findViewById(R.id.btn_closeEthPower);
        tv_screenWidth = (TextView) findViewById(R.id.tv_screenWidth);
        tv_screenHeight = (TextView) findViewById(R.id.tv_screenHeight);
        btn_screenHeight = (Button) findViewById(R.id.btn_screenHeight);
        btn_screenWidth = (Button) findViewById(R.id.btn_screenWidth);
        //eeprom
        btn_write_eeprom = (Button) findViewById(R.id.btn_write_eeprom);
        btn_read_eeprom = (Button) findViewById(R.id.btn_read_eeprom);
        tv_read_eeprom = (TextView) findViewById(R.id.tv_read_eeprom);
        et_eeprom_data = (EditText) findViewById(R.id.et_eeprom_data);
        et_deviceId = (EditText) findViewById(R.id.et_deviceId);
        et_areaId = (EditText) findViewById(R.id.et_areaId);
        et_start_addr = (EditText) findViewById(R.id.et_start_addr);
        et_size = (EditText) findViewById(R.id.et_size);
        //api version
        tv_api_version = (TextView) findViewById(R.id.tv_api_version);
        btn_get_api_version = (Button) findViewById(R.id.btn_get_api_version);
        //3G
        btn_3G_open = (Button) findViewById(R.id.btn_3G_open);
        btn_3G_close = (Button) findViewById(R.id.btn_3G_close);
        btn_3G_reset = (Button) findViewById(R.id.btn_3G_reset);
        btn_imei = (Button) findViewById(R.id.btn_imei);
        tv_imei = (TextView) findViewById(R.id.tv_imei);
        //led
        btn_led_open = (Button) findViewById(R.id.btn_led_open);
        btn_led_close = (Button) findViewById(R.id.btn_led_close);
        //led
        btn_openwifi = (Button) findViewById(R.id.btn_openwifi);
        btn_closewifi = (Button) findViewById(R.id.btn_closewifi);

        //hdmi output
        btn_hdmi_open = (Button) findViewById(R.id.btn_hdmi_open);
        btn_hdmi_close = (Button) findViewById(R.id.btn_hdmi_close);

        //audio output device
        btn_audio_speaker = (Button) findViewById(R.id.btn_audio_speaker);
        btn_audio_wired_headset = (Button) findViewById(R.id.btn_audio_wired_headset);
        btn_audio_usb_headset = (Button) findViewById(R.id.btn_audio_usb_headset);
        btn_audio_aux_digital = (Button) findViewById(R.id.btn_audio_aux_digital);
        btn_audio_bluetooth_a2dp = (Button) findViewById(R.id.btn_audio_bluetooth_a2dp);

        //usb2.0/3.0 TypeA enable/disable
        btn_usb2_open = (Button) findViewById(R.id.btn_btn_usb_typeA2_open);
        btn_usb2_close = (Button) findViewById(R.id.btn_usb_typeA2_close);
        btn_usb3_open = (Button) findViewById(R.id.btn_usb_typeA3_open);
        btn_usb3_close = (Button) findViewById(R.id.btn_usb_typeA3_close);

        //otg mode
        btn_otg_mode_slave = (Button) findViewById(R.id.btn_btn_otg_mode_slave);
        btn_otg_mode_host = (Button) findViewById(R.id.btn_btn_otg_mode_host);
        btn_otg_mode_mode = (Button) findViewById(R.id.btn_btn_otg_mode_mode);

        //touchscreen mode
        btn_ts_enable = (Button) findViewById(R.id.btn_btn_ts_enable);
        btn_ts_disable = (Button) findViewById(R.id.btn_btn_ts_disable);
        btn_ts_status = (Button) findViewById(R.id.btn_btn_ts_status);
        btn_ir_open = (Button) findViewById(R.id.btn_ir_open);
        btn_ir_close = (Button) findViewById(R.id.btn_ir_close);
        //HDMI connect status
        btn_hdmi_connect_status = (Button) findViewById(R.id.btn_hdmi_status);

        //HDMIIN connect status
//        btn_hdmiin_connect_status = (Button) findViewById(R.id.btn_hdmiin_status);
//		 btn_hdmiin_connect_status.setEnabled(false);
        // packages whitelist manager
        btn_whitelist_control = (Button) findViewById(R.id.btn_whitelist_manager_control);

        btn_three_poweronoff = (Button) findViewById(R.id.button_three_poweronoff);

        //mic
        btn_headsetmic_open = (Button) findViewById(R.id.btn_headsetmic_open);
        btn_headsetmic_close = (Button) findViewById(R.id.btn_headsetmic_close);

        btn_speaker = (Button) findViewById(R.id.btn_speaker);
        btn_output_normal = (Button) findViewById(R.id.btn_output_normal);
        //wifi white list
        btnDeleWifiWhitelist = (Button) findViewById(R.id.btn_dele_wifi_whitelist);
        btnGetWifiWhitelist = (Button) findViewById(R.id.btn_get_wifi_whitelist);
        btnRemoveWifiWhitelist = (Button) findViewById(R.id.btn_remove_wifi_whitelist);
        btnAddWifiWhitelist = (Button) findViewById(R.id.btn_add_wifi_whitelist);

        etRemoveWifiWhitelist = (EditText) findViewById(R.id.et_remove_wifi_whitelist);
        etAddWifiWhitelist = (EditText) findViewById(R.id.et_add_wifi_whitelist);
        //net whitelist
        btn_Firewall = (Button) findViewById(R.id.btn_set_firewall);
        btn_Firewall_disable = (Button) findViewById(R.id.btn_set_firewall_disable);
        btn_disabled_mobile = (Button) findViewById(R.id.btn_set_mobile_disabled);
        btn_disabled_wifi = (Button) findViewById(R.id.btn_set_wifi_disabled);
        btn_disable_eth = (Button) findViewById(R.id.btn_set_eth_disabled);

        btn_clear_mobile = (Button) findViewById(R.id.btn_clear_mobile_disabled);
        btn_clear_wifi = (Button) findViewById(R.id.btn_clear_wifi_disabled);
        btn_clear_eth = (Button) findViewById(R.id.btn_clear_eth_disabled);

        btn_get_app_whitelist = (Button) findViewById(R.id.btn_get_app_whitelist);
        btn_get_url_whitelist = (Button) findViewById(R.id.btn_get_url_whitelist);
        btn_get_app_blacklist = (Button) findViewById(R.id.btn_get_app_blacklist);
        btn_get_url_blacklist = (Button) findViewById(R.id.btn_get_url_blacklist);

        btn_app_whitelist = (Button) findViewById(R.id.btn_app_whitelist);
        btn_app_blacklist = (Button) findViewById(R.id.btn_app_blacklist);
        btn_url_whitelist = (Button) findViewById(R.id.btn_url_whitelist);
        btn_url_blacklist = (Button) findViewById(R.id.btn_url_blacklist);

        btn_net_time_limit = (Button) findViewById(R.id.btn_net_time_limit);
        btn_net_weekdays_limit = (Button) findViewById(R.id.btn_net_weekdays_limit);

        etAppWhiteList = (EditText) findViewById(R.id.et_app_whitelist);
        etAppBlackList = (EditText) findViewById(R.id.et_app_blacklist);
        etUrlWhiteList = (EditText) findViewById(R.id.et_url_whitelist);
        etUrlBlackList = (EditText) findViewById(R.id.et_url_blacklist);

        et_net_start_limit_hour = (EditText) findViewById(R.id.et_net_start_limit_hour);
        et_net_start_limit_minute = (EditText) findViewById(R.id.et_net_start_limit_minute);
        et_net_end_limit_hour = (EditText) findViewById(R.id.et_net_end_limit_hour);
        et_net_end_limit_minute = (EditText) findViewById(R.id.et_net_end_limit_minute);
        et_net_limit_weekdays = (EditText) findViewById(R.id.et_net_limit_weekdays);

        btn_keep_alive_on = (Button) findViewById(R.id.btn_keep_alive_on);
        btn_keep_alive_off = (Button) findViewById(R.id.btn_keep_alive_off);
        btn_get_keep_alive_pkg_name = (Button) findViewById(R.id.btn_get_keep_alive_pkg_name);
        btn_clear_keep_alive_pkg_name = (Button) findViewById(R.id.btn_clear_keep_alive_pkg_name);
        btn_set_keep_alive_pkg_name = (Button) findViewById(R.id.btn_set_keep_alive_pkg_name);
        et_set_keep_alive_pkg_name = (EditText) findViewById(R.id.et_set_keep_alive_pkg_name);
		btn_set_keep_alive_service_pkg = (Button) findViewById(R.id.btn_set_keep_alive_service_pkg);
		btn_get_keep_alive_service_pkg = (Button) findViewById(R.id.btn_get_keep_alive_service_pkg);
        et_set_keep_alive_service_pkg = (EditText) findViewById(R.id.et_set_keep_alive_service_pkg);
		btn_set_keep_alive_interval_time = (Button)findViewById(R.id.btn_set_keep_alive_interval_time);
        btn_get_keep_alive_interval_time = (Button)findViewById(R.id.btn_get_keep_alive_interval_time);
        et_set_keep_alive_interval_time = (EditText) findViewById(R.id.et_set_keep_alive_interval_time);
        btn_uninstall_package = findViewById(R.id.btn_uninstall_package);

        btn_uninstall_package.setOnClickListener(this);

        btn_wifi_tether_on = (Button) findViewById(R.id.btn_wifi_tether_on);
        btn_wifi_tether_off = (Button) findViewById(R.id.btn_wifi_tether_off);
        btn_wifi_tether_ssidpwd = (Button) findViewById(R.id.btn_wifi_tether_ssidpwd);
        btn_wifi_tether_ip = (Button) findViewById(R.id.btn_wifi_tether_ip);
        btn_get_wifi_tether_enabled = (Button) findViewById(R.id.btn_get_wifi_tether_enabled);
        btn_get_wifi_tether_ssid = (Button) findViewById(R.id.btn_get_wifi_tether_ssid);
        btn_get_wifi_tether_pwd = (Button) findViewById(R.id.btn_get_wifi_tether_pwd);
        btn_get_wifi_tether_ip = (Button) findViewById(R.id.btn_get_wifi_tether_ip);
        et_wifi_tether_ssid = (EditText) findViewById(R.id.et_wifi_tether_ssid);
        et_wifi_tether_pwd = (EditText) findViewById(R.id.et_wifi_tether_pwd);
        et_wifi_tether_band = (EditText) findViewById(R.id.et_wifi_tether_band);
        et_wifi_tether_ip = (EditText) findViewById(R.id.et_wifi_tether_ip);
		
		btn_set_logo = (Button)findViewById(R.id.btn_set_logo);
		btn_set_default_wallpaper = (Button)findViewById(R.id.btn_set_default_wallpaper);
		btn_set_boot_animation = (Button)findViewById(R.id.btn_set_boot_animation);
		btn_reset_boot_animation = (Button)findViewById(R.id.btn_reset_boot_animation);
		et_set_logo = (EditText)findViewById(R.id.et_set_logo);
		et_set_default_wallpaper = (EditText)findViewById(R.id.et_set_default_wallpaper);
		et_set_boot_animation = (EditText)findViewById(R.id.et_set_boot_animation);
		
		btn_set_default_locale = (Button)findViewById(R.id.btn_set_default_locale);
		btn_set_default_timezone = (Button)findViewById(R.id.btn_set_default_timezone);
		et_set_default_locale = (EditText)findViewById(R.id.et_set_default_locale);
		et_set_default_timezone = (EditText)findViewById(R.id.et_set_default_timezone);
       //scheduled power on & off
        et_poweroff_hour = (EditText) findViewById(R.id.et_poweroff_hour);
        et_poweroff_minute = (EditText) findViewById(R.id.et_poweroff_minute);
        et_poweroff_repeat_week = (EditText) findViewById(R.id.et_poweroff_repeat_week);
        spinner_poweroff_repeat_type = (Spinner) findViewById(R.id.spinner_poweroff_repeat_type);
        toggle_scheduled_poweroff = (ToggleButton) findViewById(R.id.toggle_scheduled_poweroff);
        et_poweron_hour = (EditText) findViewById(R.id.et_poweron_hour);
        et_poweron_minute = (EditText) findViewById(R.id.et_poweron_minute);
        et_poweron_repeat_week = (EditText) findViewById(R.id.et_poweron_repeat_week);
        spinner_poweron_repeat_type = (Spinner) findViewById(R.id.spinner_poweron_repeat_type);
        toggle_scheduled_poweron = (ToggleButton) findViewById(R.id.toggle_scheduled_poweron);

        et_poweroff_hour2 = (EditText) findViewById(R.id.et_poweroff_hour2);
        et_poweroff_minute2 = (EditText) findViewById(R.id.et_poweroff_minute2);
        et_poweroff_repeat_week2 = (EditText) findViewById(R.id.et_poweroff_repeat_week2);
        spinner_poweroff_repeat_type2 = (Spinner) findViewById(R.id.spinner_poweroff_repeat_type2);
        toggle_scheduled_poweroff2 = (ToggleButton) findViewById(R.id.toggle_scheduled_poweroff2);
        et_poweron_hour2 = (EditText) findViewById(R.id.et_poweron_hour2);
        et_poweron_minute2 = (EditText) findViewById(R.id.et_poweron_minute2);
        et_poweron_repeat_week2 = (EditText) findViewById(R.id.et_poweron_repeat_week2);
        spinner_poweron_repeat_type2 = (Spinner) findViewById(R.id.spinner_poweron_repeat_type2);
        toggle_scheduled_poweron2 = (ToggleButton) findViewById(R.id.toggle_scheduled_poweron2);

        btn_watchdog.setOnClickListener(this);
        btn_closedog.setOnClickListener(this);
        btn_feeddog.setOnClickListener(this);
        btn_set_watch_dog_timeout.setOnClickListener(this);
        btn_get_watch_dog_timeout.setOnClickListener(this);

        btn_USB.setOnClickListener(this);
        btn_sd.setOnClickListener(this);
        button_close.setOnClickListener(this);
        button_reboot.setOnClickListener(this);
        button_get_nettype.setOnClickListener(this);
        button_takePictrue.setOnClickListener(this);
        button_settime.setOnClickListener(this);
        button_settimebyNet.setOnClickListener(this);
        button_settimebynetoff.setOnClickListener(this);
        btn_silent_install_only.setOnClickListener(this);
        btn_silent_install_self_starting.setOnClickListener(this);
        btn_set_power_off_on_time.setOnClickListener(this);
        btn_gpio.setOnClickListener(this);
        btn_devices.setOnClickListener(this);
        btn_uart.setOnClickListener(this);
        btn_update.setOnClickListener(this);
        btn_showstatus.setOnClickListener(this);
        btn_hidestatus.setOnClickListener(this);
        btn_openback.setOnClickListener(this);
        btn_closeback.setOnClickListener(this);
        btn_volumeadd.setOnClickListener(this);
        btn_volumedec.setOnClickListener(this);
        btn_mute_restore.setOnClickListener(this);
        btn_normal.setOnClickListener(this);
        btn_openwifi.setOnClickListener(this);
        btn_closewifi.setOnClickListener(this);
        btn_one.setOnClickListener(this);
        btn_two.setOnClickListener(this);
        btn_three.setOnClickListener(this);
        btn_four.setOnClickListener(this);
		btn_hdmi_one.setOnClickListener(this);
		btn_hdmi_two.setOnClickListener(this);
		btn_hdmi_three.setOnClickListener(this);
		btn_hdmi_four.setOnClickListener(this);
        btn_io_closeback.setOnClickListener(this);
        btn_setVolume.setOnClickListener(this);
        btn_getVolume.setOnClickListener(this);
        btn_getBright.setOnClickListener(this);
        btn_openlog.setOnClickListener(this);
        btn_closelog.setOnClickListener(this);
        btn_getMac.setOnClickListener(this);
        btn_setIP.setOnClickListener(this);
        btn_dhcp.setOnClickListener(this);
        btn_getIP.setOnClickListener(this);
        btn_openUsb.setOnClickListener(this);
        btn_closeUsb.setOnClickListener(this);
        btn_getEth.setOnClickListener(this);
        btn_getback.setOnClickListener(this);
        btn_openEthPower.setOnClickListener(this);
        btn_closeEthPower.setOnClickListener(this);
        btn_screenWidth.setOnClickListener(this);
        btn_screenHeight.setOnClickListener(this);
        btn_write_eeprom.setOnClickListener(this);
        btn_read_eeprom.setOnClickListener(this);
        btn_get_api_version.setOnClickListener(this);
        //3G
        btn_3G_open.setOnClickListener(this);
        btn_3G_close.setOnClickListener(this);
        btn_3G_reset.setOnClickListener(this);
        btn_imei.setOnClickListener(this);
        //led
        btn_led_open.setOnClickListener(this);
        btn_led_close.setOnClickListener(this);

        //hdmi output
        btn_hdmi_open.setOnClickListener(this);
        btn_hdmi_close.setOnClickListener(this);

        //audio output device
        btn_audio_speaker.setOnClickListener(this);
        btn_audio_wired_headset.setOnClickListener(this);
        btn_audio_usb_headset.setOnClickListener(this);
        btn_audio_aux_digital.setOnClickListener(this);
        btn_audio_bluetooth_a2dp.setOnClickListener(this);

        //usb2.0/3.0 TypeA enable/disable
        btn_usb2_open.setOnClickListener(this);
        btn_usb2_close.setOnClickListener(this);
        btn_whitelist_control.setOnClickListener(this);
        btn_usb3_open.setOnClickListener(this);
        btn_usb3_close.setOnClickListener(this);

        //usb mode
        btn_otg_mode_slave.setOnClickListener(this);
        btn_otg_mode_host.setOnClickListener(this);
        btn_otg_mode_mode.setOnClickListener(this);

        //touchscreen
        btn_ts_enable.setOnClickListener(this);
        btn_ts_disable.setOnClickListener(this);
        btn_ts_status.setOnClickListener(this);
        btn_ir_open.setOnClickListener(this);
        btn_ir_close.setOnClickListener(this);
        //HDMI connect status
        btn_hdmi_connect_status.setOnClickListener(this);

        //HDMI connect status
//        btn_hdmiin_connect_status.setOnClickListener(this);

        btn_three_poweronoff.setOnClickListener(this);

        //led
        btn_headsetmic_open.setOnClickListener(this);
        btn_headsetmic_close.setOnClickListener(this);

        btn_speaker.setOnClickListener(this);
        btn_output_normal.setOnClickListener(this);
        //wifi white list
        btnDeleWifiWhitelist.setOnClickListener(this);
        btnGetWifiWhitelist.setOnClickListener(this);
        btnRemoveWifiWhitelist.setOnClickListener(this);
        btnAddWifiWhitelist.setOnClickListener(this);
        //net whitelist
        btn_Firewall.setOnClickListener(this);
        btn_Firewall_disable.setOnClickListener(this);
        btn_disabled_mobile.setOnClickListener(this);
        btn_disabled_wifi.setOnClickListener(this);
        btn_disable_eth.setOnClickListener(this);

        btn_clear_mobile.setOnClickListener(this);
        btn_clear_wifi.setOnClickListener(this);
        btn_clear_eth.setOnClickListener(this);

        btn_app_whitelist.setOnClickListener(this);
        btn_app_blacklist.setOnClickListener(this);
        btn_url_whitelist.setOnClickListener(this);
        btn_url_blacklist.setOnClickListener(this);

        btn_get_app_whitelist.setOnClickListener(this);
        btn_get_url_whitelist.setOnClickListener(this);
        btn_get_app_blacklist.setOnClickListener(this);
        btn_get_url_blacklist.setOnClickListener(this);

        btn_net_time_limit.setOnClickListener(this);
        btn_net_weekdays_limit.setOnClickListener(this);

        btn_keep_alive_on.setOnClickListener(this);
        btn_keep_alive_off.setOnClickListener(this);
        btn_get_keep_alive_pkg_name.setOnClickListener(this);
        btn_clear_keep_alive_pkg_name.setOnClickListener(this);
        btn_set_keep_alive_pkg_name.setOnClickListener(this);
		btn_set_keep_alive_service_pkg.setOnClickListener(this);
        btn_get_keep_alive_service_pkg.setOnClickListener(this);
        btn_set_keep_alive_interval_time.setOnClickListener(this);
        btn_get_keep_alive_interval_time.setOnClickListener(this);

        //wifi tether
        btn_wifi_tether_on.setOnClickListener(this);
        btn_wifi_tether_off.setOnClickListener(this);
        btn_wifi_tether_ssidpwd.setOnClickListener(this);
        btn_wifi_tether_ip.setOnClickListener(this);
        btn_get_wifi_tether_enabled.setOnClickListener(this);
        btn_get_wifi_tether_ssid.setOnClickListener(this);
        btn_get_wifi_tether_pwd.setOnClickListener(this);
        btn_get_wifi_tether_ip.setOnClickListener(this);
		
		btn_set_logo.setOnClickListener(this);
		btn_set_default_wallpaper.setOnClickListener(this);
		btn_set_boot_animation.setOnClickListener(this);
		btn_reset_boot_animation.setOnClickListener(this);
		
		btn_set_default_locale.setOnClickListener(this);
		btn_set_default_timezone.setOnClickListener(this);
		
        btn_can_api.setOnClickListener(this);
        spinner_poweroff_repeat_type.setOnItemSelectedListener(this);
        toggle_scheduled_poweroff.setOnCheckedChangeListener(this);
        spinner_poweron_repeat_type.setOnItemSelectedListener(this);
        toggle_scheduled_poweron.setOnCheckedChangeListener(this);

        spinner_poweroff_repeat_type2.setOnItemSelectedListener(this);
        toggle_scheduled_poweroff2.setOnCheckedChangeListener(this);
        spinner_poweron_repeat_type2.setOnItemSelectedListener(this);
        toggle_scheduled_poweron2.setOnCheckedChangeListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mCxManager = CxManager.register(this, new ICustomCallback() {
            @Override
            public void onCustomCallback(String s) {
                Log.i(TAG, s);
                String model = mCxManager.jwsGetAndroidModel();
                Log.i(TAG, "Device model is " + model);
            }
        });
        if (mCxManager == null) {
            Log.e(TAG, "mCxManager == null");
        }
        if (Util.isEthernet1Exist()) {
            ethernet_checkbox.setVisibility(View.VISIBLE);
        } else {
            ethernet_checkbox.setVisibility(View.GONE);
        }
        if (Util.isEthernet1Exist()) {
            jws_et_ethernet_checkbox.setVisibility(View.VISIBLE);
        } else {
            jws_et_ethernet_checkbox.setVisibility(View.GONE);
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        tv_imei.setText("");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_uninstall_package:
                startActivity(new Intent(this, WhitelistUninstallActivity.class));
                break;
            case R.id.button_close:
                mCxManager.jwsShutDown();
                break;
            case R.id.button_reboot:
                mCxManager.jwsReboot("reboot");
                break;
            case R.id.button_three_poweronoff:
                Calendar offTime = Calendar.getInstance();
                offTime.setTimeInMillis(System.currentTimeMillis() + 3 * 60 * 1000);
                Calendar OnTime = Calendar.getInstance();
                OnTime.setTimeInMillis(System.currentTimeMillis() + 6 * 60 * 1000);

                String stroffTime = offTime.get(Calendar.HOUR_OF_DAY) + ":" + offTime.get(Calendar.MINUTE);
                String stronTime = OnTime.get(Calendar.HOUR_OF_DAY) + ":" + OnTime.get(Calendar.MINUTE);
                mCxManager.jwsSetPowerOnOff(stroffTime, stronTime, 1);
                break;
            case R.id.set_power_off_on_time:
                String offTimeh = poweroff_hour.getText().toString();
                String offTimem = poweroff_minute.getText().toString();
                String onTimeh = poweron_hour.getText().toString();
                String onTimem = poweron_minute.getText().toString();
                String getenable = edit_enable.getText().toString().trim();

                String off = offTimeh + ":" + offTimem;
                String on = onTimeh + ":" + onTimem;

                int enable = Integer.parseInt(getenable);
                if (enable == 0) {
                    mCxManager.jwsSetPowerOnOff(null, null, enable);
                } else if (enable == 1 || enable == 2) {
                    if (CorrectHourtime(offTimeh) && CorrectHourtime(onTimeh) && CorrectMinutetime(offTimem) && CorrectMinutetime(onTimem)) {
                        mCxManager.jwsSetPowerOnOff(off, on, enable);
                    } else {
                        Toast.makeText(getApplicationContext(), "setting value error", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(getApplicationContext(), "setting value error", Toast.LENGTH_SHORT).show();
                }
                break;

            case R.id.button_get_nettype:
                String netType = mCxManager.jwsGetCurrentNetType();
                editNetType.setText(netType);
                break;
            case R.id.btn_silent_install_only:
                String path = Environment.getExternalStorageDirectory().getPath().toString() + File.separator + "Update.apk";
                Log.d(TAG, "======button_silentInstall==========path:" + path);
                if (!path.equals("")) {
                    mCxManager.jwsSilentInstallApp(path, false);
                } else {
                    Toast.makeText(getApplicationContext(), "please choose install apk", Toast.LENGTH_SHORT).show();
                }
                break;

            case R.id.btn_silent_install_self_starting:
                path = Environment.getExternalStorageDirectory().getPath().toString() + File.separator + "Update.apk";
                Log.d(TAG, "======button_silentInstall==========path:" + path);
                if (!path.equals("")) {
                    mCxManager.jwsSilentInstallApp(path, true);
                } else {
                    Toast.makeText(getApplicationContext(), "please choose install apk", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.button_takepictrue:
                Thread t2 = new Thread() {
                    @Override
                    public void run() {
                        Intent intent = new Intent(MainActivity.this, ScreenActivity.class);
                        startActivity(intent);
                        Message msg = new Message();
                        msg.what = 0x123;
                        handler.sendEmptyMessage(msg.what);
                    }
                };
                t2.start();
                break;
            case R.id.btn_gpio:
                Intent intent = new Intent(this, GpioActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_openlog:
                int Item = slogtype.getSelectedItemPosition();
                String logtype = slogtype.getItemAtPosition(Item).toString();
                mCxManager.jwsStartSystemLog(logtype);
                Toast.makeText(getApplicationContext(), "StartSystemLog", Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_closelog:
                mCxManager.jwsStopSystemLog();
                Toast.makeText(getApplicationContext(), "StopSystemLog", Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_devices:
                Intent intent1 = new Intent(this, DevicesActivity.class);
                startActivity(intent1);
                break;
            case R.id.btn_uart:
                Intent Uartintent = new Intent(this, UartActivity.class);
                startActivity(Uartintent);
                break;
            case R.id.btn_update:
	        	/*
	        	String updateimg_path[] = {
	        			"/mnt/internal_sd/update.zip",
	        			"/mnt/external_sd/update.zip",
	        			"/mnt/usb_storage/USB_DISK1/udisk2/update.zip", 
	        			"/mnt/usb_storage/USB_DISK1/udisk0/update.zip",
	        			"/mnt/usb_storage/USB_DISK1/udisk1/update.zip",
	        			"/mnt/usb_storage/USB_DISK2/udisk0/update.zip", 
	        			"/mnt/usb_storage/USB_DISK0/udisk0/update.zip"
	        			};
	        	
	        	for(int i=0; i<updateimg_path.length; i++)
	        	{
	        		File file = new File(updateimg_path[i]);
	        		//Log.d(TAG, "============111==========sdPath:" + updateimg_path[i]);
	        		if(file.exists()){       	
							try {
								Log.d(TAG, "======================sdPath:" + updateimg_path[i]);
								jws.jwsInstallPackage(getApplicationContext(), file);
							} catch (IOException e) {
								e.printStackTrace();
							}           			
	        		}else{
	        				Toast.makeText(getApplicationContext(), "please choose update.zip", Toast.LENGTH_SHORT).show();
	        		}  
	        	}
	        	
	        		String sdPath =Environment.getExternalStorageDirectory().getPath().toString() + File.separator + "update.zip";
	        		*/

                try {
                    mCxManager.jwsRebootRecovery();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case R.id.button_settime:
                String year = et_year.getText().toString();
                String month = et_month.getText().toString();
                String hourday = et_day.getText().toString();
                String hour = et_hour.getText().toString();
                String minute = et_minute.getText().toString();
                String second = et_second.getText().toString();
                if (!(year.equals("") || month.equals("") || hourday.equals("") && hour.equals("") || minute.equals("") || second.equals(""))) {
                    mCxManager.jwsSetTime(Integer.valueOf(year), Integer.valueOf(month),
                            Integer.valueOf(hourday), Integer.valueOf(hour),
                            Integer.valueOf(minute), Integer.valueOf(second));
                } else {
                    Toast.makeText(getApplicationContext(), "please input time!", Toast.LENGTH_SHORT).show();
                }

                break;
            case R.id.button_settimebynet:
                mCxManager.jwsSetTimeFromNetwork(true);
                break;
            case R.id.button_settimebynetoff:
                mCxManager.jwsSetTimeFromNetwork(false);
                break;
            case R.id.btn_openwifi:
                mCxManager.jwsWifiOpen();
                break;
            case R.id.btn_closewifi:
                mCxManager.jwsWifiClose();
                break;
            case R.id.btn_showstatus:
                mCxManager.jwsSetStatusBar(true);
                break;
            case R.id.btn_hidestatus:
                mCxManager.jwsSetStatusBar(false);
                break;
            case R.id.btn_one:
                Handler mHandler = new Handler();
                Runnable updateThread = new Runnable() {
                    public void run() {
                        mCxManager.jwsSetRotation("0");
                    }
                };
                mHandler.postDelayed(updateThread, 200);
                break;
            case R.id.btn_two:
                mCxManager.jwsSetRotation("90");
                break;
            case R.id.btn_three:
                mCxManager.jwsSetRotation("180");
                break;
            case R.id.btn_four:
                mCxManager.jwsSetRotation("270");
                break;
			case R.id.btn_hdmi_one:
				mCxManager.jwsSetHdmiRotation(0);
				break;
			case R.id.btn_hdmi_two:
				mCxManager.jwsSetHdmiRotation(1);
				break;
			case R.id.btn_hdmi_three:
				mCxManager.jwsSetHdmiRotation(2);
				break;
			case R.id.btn_hdmi_four:
				mCxManager.jwsSetHdmiRotation(3);
				break;
            case R.id.btn_openback:
                mCxManager.jwsSetLcdBackLight(1);
                break;
            case R.id.btn_closeback:
                mCxManager.jwsSetLcdBackLight(0);
                break;
            case R.id.btn_getback:
                Toast.makeText(getApplicationContext(), "lcd backLight state:" + mCxManager.jwsGetLcdLightStatus(), Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_bright:
                String bright = edit_setBright.getText().toString();
                if (!bright.equals("")) {
                    mCxManager.jwsSetBrightness(Integer.parseInt(bright));
                } else {
                    Toast.makeText(getApplicationContext(), "please input bright value", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_getBright:
                tv_bright.setText(mCxManager.jwsGetScreenBrightness() + "");
                break;
            case R.id.btn_volumeadd:
                mAudioManager.adjustStreamVolume(STREAM_MUSIC, ADJUST_RAISE, FLAG_SHOW_UI);//澧炲姞闊抽噺
                break;
            case R.id.btn_volumedec:
                mAudioManager.adjustStreamVolume(STREAM_MUSIC, ADJUST_LOWER, FLAG_SHOW_UI);//鍑忓皯闊抽噺   STREAM_RING  STREAM_MUSIC  STREAM_ALARM
                break;
            case R.id.btn_mute_restore:
                mCxManager.jwsVolumeMuteAndRestore();
                break;
            case R.id.btn_setVolume:
                String volume = edit_values.getText().toString();
                if (!volume.equals("")) {
                    mCxManager.jwsSetVolume(Integer.parseInt(volume));
                    Toast.makeText(getApplicationContext(), mCxManager.jwsSetVolume(Integer.parseInt(volume)) + "", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getApplicationContext(), "please input volume", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_getVolume:
                txt_volume_show.setText(mCxManager.jwsGetVolume() + "");
                break;
            case R.id.btn_getmac:
                if (ethernet_checkbox.isChecked()) {
                    tv_Mac.setText(mCxManager.jwsGetEthMacAddress("eth0") + "");
                } else {
                    tv_Mac.setText(mCxManager.jwsGetEthMacAddress("eth1") + "");
                }
                break;
            case R.id.btn_dhcp:
                if (ethernet_checkbox.isChecked()) {
                    mCxManager.jwsSetEthDHCPAddress("eth0");
                } else {
                    mCxManager.jwsSetEthDHCPAddress("eth1");
                }

                break;
            case R.id.btn_setIP:
                String ipAddr = edit_ipAddr.getText().toString();
                String netMask = edit_netMask.getText().toString();
                String gateway = edit_gateway.getText().toString();
                String dns1 = edit_dns1.getText().toString();
                String dns2 = edit_dns2.getText().toString();
                if (!TextUtils.isEmpty(ipAddr) && !TextUtils.isEmpty(netMask) && !TextUtils.isEmpty(gateway) && !TextUtils.isEmpty(dns1))

                    if (ethernet_checkbox.isChecked()) {
                        mCxManager.jwsSetEthStaticIPAddress("eth0", ipAddr, netMask, gateway, dns1, dns2);
                    } else {
                        mCxManager.jwsSetEthStaticIPAddress("eth1", ipAddr, netMask, gateway, dns1, dns2);
                    }
                break;
            case R.id.btn_getIP:
                if (ethernet_checkbox.isChecked()) {
                    tv_IP.setText(mCxManager.jwsGetEthIPAddress("eth0") + "");
                } else {
                    tv_IP.setText(mCxManager.jwsGetEthIPAddress("eth1") + "");
                }

                break;
            case R.id.btn_USB:
                if (ed_usb_num.getText().toString().equals("")) {
                    Toast.makeText(getApplicationContext(), "please input usb number!", Toast.LENGTH_SHORT).show();
                    return;
                }
                tv_usb.setText(mCxManager.jwsGetUSBPath(Integer.parseInt(ed_usb_num.getText().toString())));
                break;
            case R.id.btn_sd:
                String SDCardPath = mCxManager.jwsGetSDcardPath();
                if (SDCardPath != null) {
                    tv_sd.setText(SDCardPath);
                } else {
                    tv_sd.setText(getString(R.string.jws_insert_sd_card));
                }
                break;
            case R.id.btn_watchdog:
                mCxManager.jwsWatchDogEnable(1);
                break;
            case R.id.btn_closedog:
                mCxManager.jwsWatchDogKernelFeed();
                break;
            case R.id.btn_feeddog:
                mCxManager.jwsWatchDogFeed();
                break;
            case R.id.btn_set_watch_dog_timeout:
                int interval = Integer.parseInt(et_interval.getText().toString());
                int margin  = Integer.parseInt(et_margin.getText().toString());
                mCxManager.jwsWatchDogSetTimeout(interval,margin);
                break;
            case R.id.btn_get_watch_dog_timeout:
                int timeout = mCxManager.jwsWatchDogGetTimeout();
                Log.d(TAG, "GetTimeout: "+timeout);
                Toast.makeText(getApplicationContext(), "Watchdog timeout is: " + timeout + "s" , Toast.LENGTH_SHORT).show();
                break;
            case R.id.btn_openUSB:
                if (tv_usbNum.getText().toString().equals("")) {
                    Toast.makeText(getApplicationContext(), "usb number is null", Toast.LENGTH_SHORT).show();
                    return;
                }
                mCxManager.jwsSetUsbPower(1, Integer.parseInt(tv_usbNum.getText().toString()), 1);
                break;
            case R.id.btn_closeUSB:
                if (tv_usbNum.getText().toString().equals("")) {
                    Toast.makeText(getApplicationContext(), "usb number is null", Toast.LENGTH_SHORT).show();
                    return;
                }
                mCxManager.jwsSetUsbPower(1, Integer.parseInt(tv_usbNum.getText().toString()), 0);
                break;
            case R.id.btn_getEth:
                if (jws_et_ethernet_checkbox.isChecked()) {
                    boolean isEnable = mCxManager.jwsGetEthernetState("eth0");
                    if (isEnable) {
                        tv_eth.setText("open");
                    } else {
                        tv_eth.setText("close");
                    }
                } else {
                    boolean isEnable1 = mCxManager.jwsGetEthernetState("eth1");
                    if (isEnable1) {
                        tv_eth.setText("open");
                    } else {
                        tv_eth.setText("close");
                    }
                }

                break;
            case R.id.btn_openEthPower:
                if (jws_et_ethernet_checkbox.isChecked()) {
                    mCxManager.jwsSetEthernetState("eth0", true);
                } else {
                    mCxManager.jwsSetEthernetState("eth1", true);
                }

                break;
            case R.id.btn_closeEthPower:
                if (jws_et_ethernet_checkbox.isChecked()) {
                    mCxManager.jwsSetEthernetState("eth0", false);
                } else {
                    mCxManager.jwsSetEthernetState("eth1", false);
                }

                break;
            case R.id.btn_screenWidth:
                int val = mCxManager.jwsGetScreenWidth();
                tv_screenWidth.setText(val + "");
                break;
            case R.id.btn_screenHeight:
                val = mCxManager.jwsGetScreenHeight();
                tv_screenHeight.setText(val + "");
                break;
            case R.id.btn_write_eeprom:
                String strEEprom = et_eeprom_data.getText().toString();
                if (et_deviceId.getText().toString().equals("")
                        || et_areaId.getText().toString().equals("")
                        || et_start_addr.getText().toString().equals("")
                        || et_size.getText().toString().equals("")) {
                    Toast.makeText(getApplicationContext(), "please check input paremete!", Toast.LENGTH_SHORT).show();
                    return;
                }

                mCxManager.jwsWriteExtROM(Integer.parseInt(et_deviceId.getText().toString()),
                        Integer.parseInt(et_areaId.getText().toString()),
                        Integer.parseInt(et_start_addr.getText().toString()),
                        Integer.parseInt(et_size.getText().toString()),
                        strEEprom.getBytes());
                break;
            case R.id.btn_read_eeprom:
                if (et_deviceId.getText().toString().equals("")
                        || et_areaId.getText().toString().equals("")
                        || et_start_addr.getText().toString().equals("")
                        || et_size.getText().toString().equals("")) {
                    Toast.makeText(getApplicationContext(), "please check input paremete!", Toast.LENGTH_SHORT).show();
                    return;
                }

                byte[] data = mCxManager.jwsReadExtROM(Integer.parseInt(et_deviceId.getText().toString()),
                        Integer.parseInt(et_areaId.getText().toString()),
                        Integer.parseInt(et_start_addr.getText().toString()),
                        Integer.parseInt(et_size.getText().toString()));
                if (data != null) {
                    String s = new String(data).trim();
                    tv_read_eeprom.setText(s);
                } else {
                    tv_read_eeprom.setText("");
                }
                break;
            case R.id.btn_get_api_version:
                tv_api_version.setText(mCxManager.jwsGetAPIVersion());
                break;
            case R.id.btn_3G_open:
                mCxManager.jwsSetControl(9, 1);
                break;
            case R.id.btn_3G_close:
                mCxManager.jwsSetControl(9, 0);
                break;
            case R.id.btn_3G_reset:
                mCxManager.jwsSetControl(10, 0);
                break;
            case R.id.btn_imei:
                tv_imei.setText(mCxManager.jwsGetIMEI());
                break;
            case R.id.btn_led_open:
                mCxManager.jwsSetControl(5, 1);
                break;
            case R.id.btn_led_close:
                if (mCxManager == null) {
                    Log.d(TAG, "============jws is null======");
                } else
                    mCxManager.jwsSetControl(5, 0);
                break;

            case R.id.btn_headsetmic_open:
                mCxManager.jwsSetHeadsetMicOnOff(1);
                break;
            case R.id.btn_headsetmic_close:
                if (mCxManager == null) {
                    Log.d(TAG, "============jws is null======");
                } else
                    mCxManager.jwsSetHeadsetMicOnOff(0);
                break;
            case R.id.btn_speaker:
                if (mCxManager == null) {
                    Log.d(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsAudioOutputDeviceStrategy(0);
                }
                break;
            case R.id.btn_output_normal:
                if (mCxManager == null) {
                    Log.d(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsAudioOutputDeviceStrategy(1);
                }
                break;
            case R.id.btn_hdmi_open:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetHDMIOnOff(1);
                }
                break;
            case R.id.btn_hdmi_close:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetHDMIOnOff(0);
                }
                break;
            case R.id.btn_audio_speaker:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsAudioOutputDeviceSetForceUse(1);
                }
                break;
//			case R.id.btn_audio_wired_headset:
//				if (mCxManager == null){
//					Log.e(TAG, "============jws is null======");
//				} else{
//					mCxManager.jwsAudioOutputDeviceSetForceUse(2);
//				}
//				break;
//			case R.id.btn_audio_usb_headset:
//				if (mCxManager == null){
//					Log.e(TAG, "============jws is null======");
//				} else{
//					mCxManager.jwsAudioOutputDeviceSetForceUse(3);
//				}
//				break;
//			case R.id.btn_audio_aux_digital:
//				if (mCxManager == null){
//					Log.e(TAG, "============jws is null======");
//				} else{
//					mCxManager.jwsAudioOutputDeviceSetForceUse(4);
//				}
//				break;
//			case R.id.btn_audio_bluetooth_a2dp:
//				if (mCxManager == null){
//					Log.e(TAG, "============jws is null======");
//				} else{
//					mCxManager.jwsAudioOutputDeviceSetForceUse(5);
//				}
//				break;
            case R.id.btn_btn_usb_typeA2_open:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsUSBEnable(2, 1);
                }
                break;
            case R.id.btn_usb_typeA2_close:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsUSBEnable(2, 0);
                    Log.e(TAG, "============jwsUSBEnable======");
                }
                break;
            case R.id.btn_usb_typeA3_open:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsUSBEnable(3, 1);
                }
                break;
            case R.id.btn_usb_typeA3_close:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsUSBEnable(3, 0);
                }
                break;
            case R.id.btn_whitelist_manager_control:
                //	Intent intent3 = new Intent(this, WhitelistActivity.class);
                //	startActivity(intent3);
                break;
            case R.id.btn_hdmi_status:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    Toast.makeText(getApplicationContext(), "HDMI connection status: " + mCxManager.jwsGetHDMIStatus(), Toast.LENGTH_SHORT).show();
                }
                break;
//            case R.id.btn_hdmiin_status:
//                if (mCxManager == null) {
//                    Log.e(TAG, "============jws is null======");
//                } else {
//                    Toast.makeText(getApplicationContext(), "HDMI in connection status: " + mCxManager.jwsGetHDMIINStatus(), Toast.LENGTH_SHORT).show();
//                }

//                break;
            case R.id.btn_btn_otg_mode_slave:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetOtgMode("peripheral");
                }
                break;
            case R.id.btn_btn_otg_mode_host:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetOtgMode("host");
                }
                break;
            case R.id.btn_btn_otg_mode_mode:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    Toast.makeText(getApplicationContext(), "otg mode : " + mCxManager.jwsGetOtgMode(), Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_btn_ts_enable:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetTouchScreenDisable(0);
                }
                break;
            case R.id.btn_btn_ts_disable:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetTouchScreenDisable(1);
                }
                break;
            case R.id.btn_btn_ts_status:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    Toast.makeText(getApplicationContext(), "Touch screen mode : " + mCxManager.jwsGetTouchScreenDisable(), Toast.LENGTH_SHORT).show();
                }
                break;

            case R.id.btn_ir_open:
                if (mCxManager == null) {
                    Log.d(TAG, "============jws is null======");
                } else {
                    RegisterInfraredReceiver();
                }
                break;

            case R.id.btn_ir_close:
                if (mCxManager == null) {
                    Log.d(TAG, "============jws is null======");
                } else {
                    Log.d(TAG, "R.id.btn_ir_close mInfraredReceiver = " + mInfraredReceiver);
                    if (mInfraredReceiver != null) {
                        mCxManager.jwsUnregisterIRListener();
                        unregisterReceiver(mInfraredReceiver);
                        mInfraredReceiver = null;
                    }
                }
                break;
            case R.id.btn_dele_wifi_whitelist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsDeleWifiSSIDWhiteList();
                }
                break;
            case R.id.btn_get_wifi_whitelist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsGetWifiSSIDWhiteList();
                    Toast.makeText(getApplicationContext(), btnGetWifiWhitelist.getText().toString() + mCxManager.jwsGetWifiSSIDWhiteList(), Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_remove_wifi_whitelist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String wifiSSIDString = etRemoveWifiWhitelist.getText().toString();
                    List<String> wifiSSIDList = Arrays.asList(wifiSSIDString.split(","));
                    //wifiSSIDList.add(wifiSSIDString);
                    mCxManager.jwsRemoveWifiSSIDWhiteList(wifiSSIDList);
                    Toast.makeText(getApplicationContext(), btnRemoveWifiWhitelist.getText().toString() + wifiSSIDList, Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_add_wifi_whitelist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String wifiSSIDString = etAddWifiWhitelist.getText().toString();
                    List<String> wifiSSIDList = Arrays.asList(wifiSSIDString.split(","));
                    //List<String> wifiSSIDList = new ArrayList<String>();
                    //wifiSSIDList.add(wifiSSIDString);
                    mCxManager.jwsAddWifiSSIDWhiteList(wifiSSIDList);
                    Toast.makeText(getApplicationContext(), btnAddWifiWhitelist.getText().toString() + wifiSSIDList, Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_set_firewall:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetFirewallEnabled(true);
                }
                break;
            case R.id.btn_set_firewall_disable:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetFirewallEnabled(false);
                }
                break;
            case R.id.btn_set_mobile_disabled:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetMobileRuleDisabled();
                }
                break;
            case R.id.btn_set_wifi_disabled:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetWifiRuleDisabled();
                }
                break;
            case R.id.btn_set_eth_disabled:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsSetEthRuleDisabled();
                }
                break;

            case R.id.btn_clear_mobile_disabled:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsClearMobileFirewallChain();
                }
                break;
            case R.id.btn_clear_wifi_disabled:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsClearWifiFirewallChain();
                }
                break;
            case R.id.btn_clear_eth_disabled:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsClearEthFirewallChain();
                }
                break;
            case R.id.btn_get_app_whitelist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String[] awl = mCxManager.jwsGetNetAppWhiteList();
                    for (String aw : awl) {
                        Log.e(TAG, btn_get_app_whitelist.getText().toString() + aw);
                        Toast.makeText(getApplicationContext(), btn_get_app_whitelist.getText().toString() + ": " + aw, Toast.LENGTH_SHORT).show();
                    }
                }
                break;

            case R.id.btn_get_url_whitelist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String[] wl = mCxManager.jwsGetNetWhiteList();
                    for (String w : wl) {
                        Log.e(TAG, btn_get_url_whitelist.getText().toString() + w);
                        Toast.makeText(getApplicationContext(), btn_get_url_whitelist.getText().toString() + ": " + w, Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            case R.id.btn_get_app_blacklist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String[] abl = mCxManager.jwsGetNetAppBlackList();
                    for (String ab : abl) {
                        Log.e(TAG, btn_get_app_blacklist.getText().toString() + ab);
                        Toast.makeText(getApplicationContext(), btn_get_app_blacklist.getText().toString() + ": " + ab, Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            case R.id.btn_get_url_blacklist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String[] bl = mCxManager.jwsGeNetBlackList();
                    for (String b : bl) {
                        Log.e(TAG, btn_get_url_blacklist.getText().toString() + b);
                        Toast.makeText(getApplicationContext(), btn_get_url_blacklist.getText().toString() + ": " + b, Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            case R.id.btn_app_whitelist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String appWhiteString = etAppWhiteList.getText().toString();
                    ArrayList<String> appWhiteList = new ArrayList<String>();
                    appWhiteList.add(appWhiteString);
                    mCxManager.jwsSetNetAppWhiteList(appWhiteList);
                }
                break;
            case R.id.btn_url_whitelist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String urlWhiteString = etUrlWhiteList.getText().toString();
                    ArrayList<String> urlpWhiteList = new ArrayList<String>();
                    urlpWhiteList.add(urlWhiteString);
                    mCxManager.jwsSetNetWhiteList(urlpWhiteList);
                }
                break;
            case R.id.btn_app_blacklist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String appBlackString = etAppBlackList.getText().toString();
                    ArrayList<String> appBlackList = new ArrayList<String>();
                    appBlackList.add(appBlackString);
                    mCxManager.jwsSetNetAppBlackList(appBlackList);
                }
                break;
            case R.id.btn_url_blacklist:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String urlBlackString = etUrlBlackList.getText().toString();
                    ArrayList<String> urlpBlackList = new ArrayList<String>();
                    urlpBlackList.add(urlBlackString);
                    mCxManager.jwsSetNetBlackList(urlpBlackList);
                }
                break;

            case R.id.btn_net_time_limit:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String startHourString = et_net_start_limit_hour.getText().toString().trim();
                    String startMinuteString = et_net_start_limit_minute.getText().toString().trim();
                    String endHourString = et_net_end_limit_hour.getText().toString().trim();
                    String endMinuteString = et_net_end_limit_minute.getText().toString().trim();
                    if (startHourString.equals("") || startMinuteString.equals("")
                            || endHourString.equals("") || endMinuteString.equals("")) {
                        Toast.makeText(getApplicationContext(), "please check input paremete!", Toast.LENGTH_SHORT).show();
                        return;
                    }


                    int startHour = Integer.parseInt(startHourString) - 8;
                    int startMinute = Integer.parseInt(startMinuteString);
                    int endHour = Integer.parseInt(endHourString) - 8;
                    int endMinute = Integer.parseInt(endMinuteString);

                    String startTime = startHour + ":" + startMinuteString;
                    String endTime = endHour + ":" + endMinuteString;

                    if ((startHour >= 0 && startHour <= 23) && (startMinute >= 0 && startMinute <= 59) && (endHour >= 0 && endHour <= 23) &&
                            (endMinute >= 0 && endMinute <= 59)) {
                        mCxManager.jwsSetNetTimeLimit(startTime, endTime);
                    } else {
                        Toast.makeText(getApplicationContext(), "请设置有效时间", Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            case R.id.btn_net_weekdays_limit:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String startHourString = et_net_start_limit_hour.getText().toString().trim();
                    String startMinuteString = et_net_start_limit_minute.getText().toString().trim();
                    String endHourString = et_net_end_limit_hour.getText().toString().trim();
                    String endMinuteString = et_net_end_limit_minute.getText().toString().trim();
                    String weekdays = et_net_limit_weekdays.getText().toString().trim();
                    if (startHourString.equals("") || startMinuteString.equals("")
                            || endHourString.equals("") || endMinuteString.equals("")
                            || weekdays.equals("")) {
                        Toast.makeText(getApplicationContext(), "please check input paremete!", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    int startHour = Integer.parseInt(startHourString) - 8;
                    int startMinute = Integer.parseInt(startMinuteString);
                    int endHour = Integer.parseInt(endHourString) - 8;
                    int endMinute = Integer.parseInt(endMinuteString);

                    String startTime = startHour + ":" + startMinuteString;
                    String endTime = endHour + ":" + endMinuteString;

                    if ((startHour >= 0 && startHour <= 23) && (startMinute >= 0 && startMinute <= 59) && (endHour >= 0 && endHour <= 23) &&
                            (endMinute >= 0 && endMinute <= 59)) {
                        mCxManager.jwsSetNetWeekdaysLimit(startTime, endTime, weekdays);
                    } else {
                        Toast.makeText(getApplicationContext(), "请设置有效时间", Toast.LENGTH_SHORT).show();
                    }

                }
                break;
            case R.id.btn_keep_alive_on:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsKeepAliveEnabled(true);

                }
                break;
            case R.id.btn_keep_alive_off:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsKeepAliveEnabled(false);
                }
                break;
            case R.id.btn_set_keep_alive_pkg_name:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String pkgNameStr = et_set_keep_alive_pkg_name.getText().toString();
                    mCxManager.jwsSetKeepAlivepackageName(pkgNameStr);
                }
                break;
            case R.id.btn_get_keep_alive_pkg_name:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String pkgName = mCxManager.jwsGetKeepAlivepackageName();
                    Toast.makeText(getApplicationContext(), "应用保活包名: " + pkgName, Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_clear_keep_alive_pkg_name:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsClearKeepAlivepackageName();
                }
                break;
			case R.id.btn_set_keep_alive_service_pkg:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String pkgNameStr = et_set_keep_alive_service_pkg.getText().toString();
                    mCxManager.jwsSetKeepAliveServicePkg(pkgNameStr);
                }
                break;
            case R.id.btn_get_keep_alive_service_pkg:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String pkgName = mCxManager.jwsGetKeepAliveServicePkg();
                    Toast.makeText(getApplicationContext(), "后台服务保活包名: " + pkgName, Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_set_keep_alive_interval_time:
                if (mCxManager == null){
                    Log.e(TAG, "============jws is null======");
                } else{
                    String timeStr = et_set_keep_alive_interval_time.getText().toString();
                    mCxManager.jwsSetKeepAliveIntervalTime(Integer.parseInt(timeStr));
                }
                break;
            case R.id.btn_get_keep_alive_interval_time:
                if (mCxManager == null){
                    Log.e(TAG, "============jws is null======");
                } else{
                    int time = mCxManager.jwsGetKeepAliveIntervalTime();
                    Toast.makeText(getApplicationContext(), "保活时间: "+ time, Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_wifi_tether_on:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsWifiTetherEnabled(true);
                }
                break;
            case R.id.btn_wifi_tether_off:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    mCxManager.jwsWifiTetherEnabled(false);
                }
                break;
            case R.id.btn_wifi_tether_ssidpwd:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String ssid = et_wifi_tether_ssid.getText().toString();
                    String pwd = et_wifi_tether_pwd.getText().toString();
                    String band = et_wifi_tether_band.getText().toString();
                    if (ssid != null || pwd != null || band != null) {
                        if (pwd.length() < 8 || pwd.length() > 63) {
                            Toast.makeText(getApplicationContext(), "密码长度必须至少为8位且不超过63位.", Toast.LENGTH_SHORT).show();
                        } else {
                            mCxManager.jwsSetWifiTetherSsidPwd(ssid, pwd, Integer.parseInt(band));
                        }
                    } else {
                        Toast.makeText(getApplicationContext(), "热点ssid,密码和频段不能为空!", Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            case R.id.btn_wifi_tether_ip:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    String ip = et_wifi_tether_ip.getText().toString();
                    mCxManager.jwsSetWifiTetherIp(ip);
                }
                break;
            case R.id.btn_get_wifi_tether_enabled:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    Toast.makeText(getApplicationContext(), "wifi热点开关状态:" + mCxManager.jwsGetWifiTetherEnabled(), Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_get_wifi_tether_ssid:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    Toast.makeText(getApplicationContext(), "wifi热点ssid:" + mCxManager.jwsGetWifiTetherSsid(), Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_get_wifi_tether_pwd:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    Toast.makeText(getApplicationContext(), "wifi热点密码:" + mCxManager.jwsGetWifiTetherPwd(), Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_get_wifi_tether_ip:
                if (mCxManager == null) {
                    Log.e(TAG, "============jws is null======");
                } else {
                    Toast.makeText(getApplicationContext(), "wifi热点ip:" + mCxManager.jwsGetWifiTetherIp(), Toast.LENGTH_SHORT).show();
                }
                break;
			case R.id.btn_set_logo:
				if (mCxManager == null){
					Log.e(TAG, "============jws is null======");
				} else{
					String logoPath = et_set_logo.getText().toString();
					mCxManager.jwsSetLogo(logoPath);
				}
				break;
			case R.id.btn_set_default_wallpaper:
				if (mCxManager == null){
					Log.e(TAG, "============jws is null======");
				} else{
					String wallpaperPath = et_set_default_wallpaper.getText().toString();
					mCxManager.jwsSetDefaultWallpaper(wallpaperPath);
				}
				break;
			case R.id.btn_set_boot_animation:
				if (mCxManager == null){
					Log.e(TAG, "============jws is null======");
				} else{
					String animaPath = et_set_boot_animation.getText().toString();
					mCxManager.jwsSetBootAnimation(animaPath);
				}
				break;
			case R.id.btn_reset_boot_animation:
				if (mCxManager == null){
					Log.e(TAG, "============jws is null======");
				} else{
					mCxManager.jwsResetBootAnimation();
				}
				break;		
			case R.id.btn_set_default_locale:
				if (mCxManager == null){
					Log.e(TAG, "============jws is null======");
				} else{
					String locale = et_set_default_locale.getText().toString();
                    mCxManager.jwsSetDefaultLocaleLanguage(locale);
				}
				break;
			case R.id.btn_set_default_timezone:
				if (mCxManager == null){
					Log.e(TAG, "============jws is null======");
				} else{
					String timeZone = et_set_default_timezone.getText().toString();
                    mCxManager.jwsSetDefaultTimeZone(timeZone);
				}
				break;									
            case R.id.btn_can_api:
                Intent intent3 = new Intent(this, CanActivity.class);
                startActivity(intent3);
				break;
            default:
                break;
        }

    }

    public void RegisterInfraredReceiver() {
        Log.d(TAG, "RegisterInfraredReceiver ");
        mInfraredReceiver = new jwsInfraredReceiver();
        IntentFilter intentFilter = new IntentFilter(REQUEST_RESPONSE_IR_STATE_ACTION);
        registerReceiver(mInfraredReceiver, intentFilter);
        mCxManager.jwsRegisterIRListener();
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean isCheck) {
        switch (compoundButton.getId()) {
            case R.id.toggle_scheduled_poweroff:
                String str_hour = et_poweroff_hour.getText().toString();
                String str_min = et_poweroff_minute.getText().toString();
                if (str_hour != null && str_hour.length() > 0 && str_min != null && str_min.length() > 0) {
                    int hour = Integer.parseInt(str_hour);
                    int min = Integer.parseInt(str_min);
                    if (mPoweroffRepeatType == 0 || mPoweroffRepeatType == 1) {
                        mCxManager.jwsSetScheduledPowerOff(isCheck, hour, min, mPoweroffRepeatType, null);
                    } else if (mPoweroffRepeatType == 2) {
                        String str_week = et_poweroff_repeat_week.getText().toString();
                        if (str_week != null && str_week.length() > 0) {
                            String[] strWeekArr = str_week.split(",");
                            int length = strWeekArr.length;
                            int[] weekArr = new int[length];
                            for (int i = 0; i < length; i++) {
                                weekArr[i] = Integer.parseInt(strWeekArr[i]);
                            }
                            mCxManager.jwsSetScheduledPowerOff(isCheck, hour, min, mPoweroffRepeatType, weekArr);
                        } else {
                            toggle_scheduled_poweroff.setChecked(false);
                            Toast.makeText(getApplicationContext(), "Setting value error", Toast.LENGTH_SHORT).show();
                        }

                    }
                } else {
                    toggle_scheduled_poweroff.setChecked(false);
                    Toast.makeText(getApplicationContext(), "Setting value error", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.toggle_scheduled_poweron:
                str_hour = et_poweron_hour.getText().toString();
                str_min = et_poweron_minute.getText().toString();
                if (str_hour != null && str_hour.length() > 0 && str_min != null && str_min.length() > 0) {
                    int hour = Integer.parseInt(str_hour);
                    int min = Integer.parseInt(str_min);
                    if (mPoweronRepeatType == 0 || mPoweronRepeatType == 1) {
                        mCxManager.jwsSetScheduledPowerOn(isCheck, hour, min, mPoweronRepeatType, null);
                    } else if (mPoweronRepeatType == 2) {
                        String str_week = et_poweron_repeat_week.getText().toString();
                        if (str_week != null && str_week.length() > 0) {
                            String[] strWeekArr = str_week.split(",");
                            int length = strWeekArr.length;
                            int[] weekArr = new int[length];
                            for (int i = 0; i < length; i++) {
                                weekArr[i] = Integer.parseInt(strWeekArr[i]);
                            }
                            mCxManager.jwsSetScheduledPowerOn(isCheck, hour, min, mPoweronRepeatType, weekArr);
                        } else {
                            toggle_scheduled_poweron.setChecked(false);
                            Toast.makeText(getApplicationContext(), "Setting value error", Toast.LENGTH_SHORT).show();
                        }

                    }
                } else {
                    toggle_scheduled_poweron.setChecked(false);
                    Toast.makeText(getApplicationContext(), "Setting value error", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.toggle_scheduled_poweroff2:
                str_hour = et_poweroff_hour2.getText().toString();
                str_min = et_poweroff_minute2.getText().toString();
                if (str_hour != null && str_hour.length() > 0 && str_min != null && str_min.length() > 0) {
                    int hour = Integer.parseInt(str_hour);
                    int min = Integer.parseInt(str_min);
                    if (mPoweroffRepeatType2 == 0 || mPoweroffRepeatType2 == 1) {
                        mCxManager.jwsSetScheduledPowerOff2(isCheck, hour, min, mPoweroffRepeatType2, null);
                    } else if (mPoweroffRepeatType2 == 2) {
                        String str_week = et_poweroff_repeat_week2.getText().toString();
                        if (str_week != null && str_week.length() > 0) {
                            String[] strWeekArr = str_week.split(",");
                            int length = strWeekArr.length;
                            int[] weekArr = new int[length];
                            for (int i = 0; i < length; i++) {
                                weekArr[i] = Integer.parseInt(strWeekArr[i]);
                            }
                            mCxManager.jwsSetScheduledPowerOff2(isCheck, hour, min, mPoweroffRepeatType2, weekArr);
                        } else {
                            toggle_scheduled_poweroff2.setChecked(false);
                            Toast.makeText(getApplicationContext(), "Setting value error", Toast.LENGTH_SHORT).show();
                        }

                    }
                } else {
                    toggle_scheduled_poweroff2.setChecked(false);
                    Toast.makeText(getApplicationContext(), "Setting value error", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.toggle_scheduled_poweron2:
                str_hour = et_poweron_hour2.getText().toString();
                str_min = et_poweron_minute2.getText().toString();
                if (str_hour != null && str_hour.length() > 0 && str_min != null && str_min.length() > 0) {
                    int hour = Integer.parseInt(str_hour);
                    int min = Integer.parseInt(str_min);
                    if (mPoweronRepeatType2 == 0 || mPoweronRepeatType2 == 1) {
                        mCxManager.jwsSetScheduledPowerOn2(isCheck, hour, min, mPoweronRepeatType2, null);
                    } else if (mPoweronRepeatType2 == 2) {
                        String str_week = et_poweron_repeat_week2.getText().toString();
                        if (str_week != null && str_week.length() > 0) {
                            String[] strWeekArr = str_week.split(",");
                            int length = strWeekArr.length;
                            int[] weekArr = new int[length];
                            for (int i = 0; i < length; i++) {
                                weekArr[i] = Integer.parseInt(strWeekArr[i]);
                            }
                            mCxManager.jwsSetScheduledPowerOn2(isCheck, hour, min, mPoweronRepeatType2, weekArr);
                        } else {
                            toggle_scheduled_poweron2.setChecked(false);
                            Toast.makeText(getApplicationContext(), "Setting value error", Toast.LENGTH_SHORT).show();
                        }

                    }
                } else {
                    toggle_scheduled_poweron2.setChecked(false);
                    Toast.makeText(getApplicationContext(), "Setting value error", Toast.LENGTH_SHORT).show();
                }
                break;
        }

    }

    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
        switch (adapterView.getId()) {
            case R.id.spinner_poweroff_repeat_type:
                switch (i) {
                    case 0:
                        mPoweroffRepeatType = 0;
                        et_poweroff_repeat_week.setVisibility(View.GONE);
                        break;
                    case 1:
                        mPoweroffRepeatType = 1;
                        et_poweroff_repeat_week.setVisibility(View.GONE);
                        break;
                    case 2:
                        mPoweroffRepeatType = 2;
                        et_poweroff_repeat_week.setVisibility(View.VISIBLE);
                        break;
                }
                break;
            case R.id.spinner_poweron_repeat_type:
                switch (i) {
                    case 0:
                        mPoweronRepeatType = 0;
                        et_poweron_repeat_week.setVisibility(View.GONE);
                        break;
                    case 1:
                        mPoweronRepeatType = 1;
                        et_poweron_repeat_week.setVisibility(View.GONE);
                        break;
                    case 2:
                        mPoweronRepeatType = 2;
                        et_poweron_repeat_week.setVisibility(View.VISIBLE);
                        break;
                }
                break;
            case R.id.spinner_poweroff_repeat_type2:
                switch (i) {
                    case 0:
                        mPoweroffRepeatType2 = 0;
                        et_poweroff_repeat_week2.setVisibility(View.GONE);
                        break;
                    case 1:
                        mPoweroffRepeatType2 = 1;
                        et_poweroff_repeat_week2.setVisibility(View.GONE);
                        break;
                    case 2:
                        mPoweroffRepeatType2 = 2;
                        et_poweroff_repeat_week2.setVisibility(View.VISIBLE);
                        break;
                }
                break;
            case R.id.spinner_poweron_repeat_type2:
                switch (i) {
                    case 0:
                        mPoweronRepeatType2 = 0;
                        et_poweron_repeat_week2.setVisibility(View.GONE);
                        break;
                    case 1:
                        mPoweronRepeatType2 = 1;
                        et_poweron_repeat_week2.setVisibility(View.GONE);
                        break;
                    case 2:
                        mPoweronRepeatType2 = 2;
                        et_poweron_repeat_week2.setVisibility(View.VISIBLE);
                        break;
                }
                break;
        }

    }

    @Override
    public void onNothingSelected(AdapterView<?> adapterView) {

    }

    class jwsInfraredReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean state = intent.getBooleanExtra(EXTRA_IR_STATE_RESPONSE, false);
            Log.d(TAG, "Infrared state " + state);
            if (state) {
                Toast.makeText(getApplicationContext(), getResources().getString(R.string.jws_ir_near), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), getResources().getString(R.string.jws_ir_far), Toast.LENGTH_SHORT).show();
            }
        }
    }


    public void jwsRebootRecovery(Context context) {
        File RECOVERY_DIR = new File("/cache/recovery");
        File COMMAND_FILE = new File(RECOVERY_DIR, "command");
        String SHOW_TEXT = "--show_text";
        RECOVERY_DIR.mkdirs();
        // In case we need it                   COMMAND_FILE.delete();
        // In case it's not writable
        try {
            FileWriter command = new FileWriter(COMMAND_FILE);
            command.write(SHOW_TEXT);
            command.write("\n");
            command.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        pm.reboot("recovery");
    }


//	public void jwsInstallPackage(Context context, File packageFile) throws IOException
//	{
//		File RECOVERY_DIR = new File("/cache/recovery");
//	    File COMMAND_FILE = new File(RECOVERY_DIR, "command");
//		String filename = packageFile.getCanonicalPath();
//		String arg = "--update_package=" + filename;
//		String SHOW_TEXT="--show_text";
//		RECOVERY_DIR.mkdirs();
//		FileWriter command = new FileWriter(COMMAND_FILE);
//		try {
//			//command.write(arg);
//			command.write(SHOW_TEXT);
//			command.write("\n");
//			command.close();
//		}catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//		PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//		pm.reboot("recovery");
//	}
//

    public String getMipsDualResolution(Activity ctx) {
        DisplayManager mDisplayManager = (DisplayManager) ctx.getSystemService(Context.DISPLAY_SERVICE);
        Display[] displays = mDisplayManager.getDisplays();
        DisplayMetrics mDisplayMetrics = new DisplayMetrics();


        if (displays.length == 1) {
            displays[0].getRealMetrics(mDisplayMetrics);
            int width = mDisplayMetrics.widthPixels;
            int height = mDisplayMetrics.heightPixels;
            Log.i(TAG, "length == 1 getMipsDualResolution: lvds w" + width);
            Log.i(TAG, "length == 1 getMipsDualResolution: lvds h" + height);
            return "LVDS_" + width + "*" + height;
        } else if (displays.length == 2) {
            displays[0].getRealMetrics(mDisplayMetrics);
            int width_1 = mDisplayMetrics.widthPixels;
            int height_1 = mDisplayMetrics.heightPixels;

            displays[1].getRealMetrics(mDisplayMetrics);
            int width_2 = mDisplayMetrics.widthPixels;
            int height_2 = mDisplayMetrics.heightPixels;
            Log.i(TAG, "getMipsDualResolution: lvds w" + width_1);
            Log.i(TAG, "getMipsDualResolution: lvds h" + height_1);
            Log.i(TAG, "getMipsDualResolution: hdmi w" + width_2);
            Log.i(TAG, "getMipsDualResolution: hdmi h" + height_2);
            return "LVDS_" + width_1 + "*" + height_1 + "," + "HDMI_" + width_2 + "*" + height_2;
        }

        return null;
    }

    private boolean CorrectHourtime(String hour) {
        int hourtime = Integer.parseInt(hour);
        if (hourtime >= 0 && hourtime <= 23)
            return true;

        return false;
    }

    private boolean CorrectMinutetime(String minute) {
        int minutetime = Integer.parseInt(minute);
        if (minutetime >= 0 && minutetime <= 59)
            return true;

        return false;
    }

}

